
package com.aurora.app.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.aurora.app.dao.PayOrderDao;
import com.aurora.app.dao.UserAccountDao;
import com.aurora.app.entity.PayOrder;
import com.aurora.app.entity.UserAccount;
import com.aurora.app.exption.NullEntityException;
import com.aurora.base.dao.BaseDao;
import com.aurora.base.service.BaseService;


/**
 * 用户账号逻辑
 * @author yongjiang.lin
 *
 */
@Service
public class UserAccountService extends BaseService<UserAccount> {

	@Resource
	private UserAccountDao baseDao;
	@Resource
	private PayOrderDao payOrderDao;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.tentcoo.base.service.impl.AbstractBaseServiceImpl#getBaseDao()
	 */
	@Override
	public BaseDao<UserAccount> getBaseDao() {
		return this.baseDao;
	}

	public UserAccount getByUserid(String userId) {
		List<UserAccount> list = this.baseDao.list(" o.user.id=?", userId);
		if (list.size() == 0) {
			return null;
		} else {
			return list.get(0);
		}

	}
	/**
	 * 获取用户账户
	 * @param payorder 订单类
	 * @return 存在返回实体，不存在返回null
	 */
	public UserAccount getAccount(PayOrder payOrder){
		List<UserAccount> list = this.baseDao.list(" o.user.id=? and o.isDelete = 0", payOrder.getThing().getUser().getId());
		if (list.size() == 0) {
			return null;
		} else {
			return list.get(0);
		}
	}

}
